<template>
	<view>
		<view class="list">
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate father_flex">
						<text style="font-size: 25upx;font-weight:550;color:#555">股权单价</text>
						<text>{{res.gqdj}}</text>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate father_flex">
						<text style="font-size: 25upx;font-weight:550;color:#555">剩余股权</text>
						<text>{{res.sygq}}</text>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate father_flex">
						<text style="font-size: 25upx;font-weight:550;color:#555">股权起兑</text>
						<text>{{res.dsqd}}</text>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate father_flex">
						<text style="font-size: 25upx;font-weight:550;color:#555">我的股权余额</text>
						<text>{{res.guquan}}</text>
					</view>
				</view>
			</view>
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-navigate">
						<text style="font-size: 25upx;font-weight:550;color:#555">股权数量</text>
						<input type="number" placeholder="请输入要兑换的股权数量" placeholder-style="color:#bbb; font-size:26upx; font-weight:100" style="background: transparent; padding-right: 140upx;" v-model="gqsl"/>
					</view>
				</view>
			</view>
				
		</view>
		<view>
			提示：您好，根据当前期股价，至少需要10000股权余额才能兑换成功！
		</view>
		<view class="btn">
			<button class="logout" @click="logout">{{sub}}</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sub:'提交',
				gqsl:'',
				res:[],
				openid:'',
				active:"active"
			};
		},
		onLoad:function(){
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../login/login'
					});
				}
			});
		},
		methods:{
			setAjax(){
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.guquan&app=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: (res) => {
						console.log(res)
						this.res = res.data
						uni.hideLoading()
					},
					fail: () => {},
					complete: () => {}
				});
			},
			logout(){
				if(this.gqsl =='') {
					this.sub = '请填写股权数量'
					uni.showModal({
						content: '请填写股权数量',
						showCancel: false,
						confirmColor:"#DD524D",
					})
					return
				}
				if((this.gqsl*this.res.gqdj) < this.res.zhishao) {
					this.sub = '股权兑换' +this.res.dsqd+ '起兑'
					uni.showModal({
						content: '股权兑换' +this.res.dsqd+ '起兑',
						showCancel: false,
						confirmColor:"#DD524D",
					})
					return
				}
				if(this.res.guquan < (this.gqsl*this.res.gqdj)) {
					this.sub = '您的股权余额不足'
					uni.showModal({
						content: '您的股权余额不足' ,
						showCancel: false,
						confirmColor:"#DD524D",
					})
					return
				}
				var beishu = this.gqsl%this.res.dsqd
				if (beishu!= 0) {
					this.sub = '兑换数量只能为' +this.res.dsqd+ '的倍数哦!'
					uni.showModal({
						content: '兑换数量只能为' +this.res.dsqd+ '的倍数哦!',
						showCancel: false,
						confirmColor:"#DD524D",
					})
					return
				}
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.guquan.duihuan&app=1',
					method: 'POST',
					data: {'openid':this.openid,'gqsl':this.gqsl},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: (res) => {
						uni.hideLoading()
					},
					fail: () => {},
					complete: () => {}
				});
			}
			
		}
	}
</script>

<style>
	.btn {padding:20upx 0;}
	.btn button {margin:20upx 0;font-size:28upx;padding:12upx;}
	.btn .logout {border-color:#175e3c;background-image: linear-gradient(to bottom, rgb(243, 109, 31), rgb(252, 9, 9));color: #fff;}
	.father_flex {display: flex;}
	.father_flex text:nth-child(1) {
		flex: 2;
	}
	.father_flex text:nth-child(2) {
		flex: 5;
	}
	.list {float:left;width:100%;padding:28upx 0;position:relative;}
	.uni-list-cell.active {background:#f5f5f5;}
	.uni-list image {width:34upx;height:34upx;}
	.uni-list .text {position:absolute;left:84upx;font-size:26upx;}
	.uni-list {margin-top:20upx;}
	.uni-list:before,.uni-list:after {display:none;}
	.uni-list-cell:after {content:" ";position:absolute;left:0.5rem;right:0.5rem;bottom:-1px;height:1px;border-top:1px solid #ebebeb;color:#D9D9D9;-webkit-transform-origin:0 0;-ms-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleY(0.5);-ms-transform:scaleY(0.5);transform:scaleY(0.5);background:none;}
	.uni-list-cell .right {font-size:24upx;color:#999;margin-right:20upx;}
	.uni-list .uni-list-cell:last-child:after {border:0;}
	.uni-list .uni-badge {margin-right:15px;background-color:#f55;}
</style>
